package com.view.cn.mvprxjava.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.view.cn.mvprxjava.R;
import com.view.cn.mvprxjava.utils.ToastUtils;
import com.view.cn.mvprxjava.view.BackgammonGameView;

/**
 * 五子棋游戏
 * Created by Administrator on 2016/12/7 0013.
 */
public class BackgammonViewFragment extends BaseFragment implements BackgammonGameView.OnGameOverLisenter {


	public static final String TAG = BackgammonViewFragment.class.getSimpleName();
	private RelativeLayout mActivityMain;
	private TextView mTv;
	private BackgammonGameView mLockView;

	public static BackgammonViewFragment newInstance() {
		BackgammonViewFragment fragment = new BackgammonViewFragment();
		return fragment;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_backgammon, container, false);

		initView(view);
		return view;
	}

	private void initView(View view) {
		mLockView = (BackgammonGameView) view.findViewById(R.id.lockView);
		mTv = (TextView) view.findViewById(R.id.tv);
		mLockView.setOnGameOverLisenter(this);
		mTv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mLockView.resetGame();
				mLockView.invaliDate();
			}
		});
	}

	@Override
	public void isGameOver(int mGameOverState) {
		String t = null;
		switch (mGameOverState) {
			case BackgammonGameView.GAMEOVER_WHITE_WINNER:
				t = "白棋选手胜利";
				break;
			case BackgammonGameView.GAMEOVER_BLACK_WINNER:
				t = "黑棋选手胜利";
				break;
			case BackgammonGameView.GAMEOVER_DRAW:
				t = "平局";
				break;
		}
		ToastUtils.getInstance().showToast(getActivity(), t);
	}

	@Override
	public void isWihte(boolean isWhite) {
		ToastUtils.getInstance().showToast(getActivity(), "白棋手：" + isWhite);
	}
}
